#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

int get(string c, int b)
{
    int ret = 0;
    for (auto tmp : c)
    {
        ret = ret * b + tmp - '0';
    }
    return ret;
}

int main()
{
    string a, b;
    cin >> a >> b;
    unordered_set<int> d;

    for (auto &x : a)
    {
        x ^= 1;
        d.insert(get(a, 2));
        x ^= 1;
    }
    for (auto &x : b)
    {
        char t = x;
        for (int i = 0; i < 3; ++i)
        {
            if (i != t - '0')
            {
                x = i + '0';
                int tmp = get(b, 3);
                if (d.count(tmp))
                {
                    cout << tmp << endl;
                    return 0;
                }
            }
            x = t;
        }
    }
    return 0;
}